﻿<!-- Views/Employee/PracticeHistory.cshtml -->
@model List<WebApplication1.Models.PracticeSession>

@{
    ViewBag.Title = WebApplication1.Utilities.LanguageManager.GetText("PracticeHistory") + " - " + WebApplication1.Utilities.LanguageManager.GetText("ExamTitle");
}

<div class="container">
    <div class="row">
        <div class="col-12">
            <div class="page-header mb-4">
                <h2 class="text-success">
                    <i class="glyphicon glyphicon-book"></i>
                    @WebApplication1.Utilities.LanguageManager.GetText("PracticeHistory")
                </h2>
            </div>
        </div>
    </div>

    @if (Model != null && Model.Count > 0)
    {
        <div class="card border-success">
            <div class="card-header bg-success text-white">
                <h5 class="mb-0">
                    <i class="glyphicon glyphicon-th-list me-2"></i>
                    @WebApplication1.Utilities.LanguageManager.GetText("PracticeRecords")
                </h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead class="table-dark">
                            <tr>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("ExamName")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("StartTime")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("EndTime")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("TotalQuestions")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("CorrectAnswers")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("Accuracy")</th>
                                <th>@WebApplication1.Utilities.LanguageManager.GetText("Action")</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var session in Model)
                            {
                                <tr>
                                    <td>
                                        <strong>@session.Exam.ExamName</strong>
                                        @if (!string.IsNullOrEmpty(session.Exam.Description))
                                        {
                                            <br /><small class="text-muted">@session.Exam.Description</small>
                                        }
                                    </td>
                                    <td>
                                        <span class="badge bg-info">@session.StartTime.ToString("yyyy-MM-dd HH:mm")</span>
                                    </td>
                                    <td>
                                        @if (session.EndTime.HasValue)
                                        {
                                            <span class="badge bg-success">@session.EndTime.Value.ToString("yyyy-MM-dd HH:mm")</span>
                                        }
                                        else
                                        {
                                            <span class="badge bg-warning">@WebApplication1.Utilities.LanguageManager.GetText("InProgress")</span>
                                        }
                                    </td>
                                    <td>
                                        <span class="badge bg-primary">@session.TotalQuestions</span>
                                    </td>
                                    <td>
                                        <span class="badge bg-success">@session.CorrectAnswers</span>
                                    </td>
                                    <td>
                                        @{
                                            var accuracy = session.TotalQuestions > 0 ? (double)session.CorrectAnswers / session.TotalQuestions * 100 : 0;
                                        }
                                        <div class="d-flex flex-column">
                                            <span class="fw-bold">@accuracy.ToString("F1")%</span>
                                            <div class="progress mt-1" style="height: 8px;">
                                                <div class="progress-bar @(accuracy >= 80 ? "bg-success" : (accuracy >= 60 ? "bg-warning" : "bg-danger"))"
                                                     role="progressbar"
                                                     style="width: @accuracy%"
                                                     aria-valuenow="@accuracy"
                                                     aria-valuemin="0"
                                                     aria-valuemax="100">
                                                </div>
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="@Url.Action("PracticeDetails", "Employee", new { id = session.SessionId })"
                                           class="btn btn-info btn-sm">
                                            <i class="glyphicon glyphicon-eye-open"></i>
                                            @WebApplication1.Utilities.LanguageManager.GetText("ViewDetails")
                                        </a>
                                        @if (!session.EndTime.HasValue)
                                        {
                                            <a href="@Url.Action("StartPractice", "Employee", new { id = session.ExamId })"
                                               class="btn btn-success btn-sm">
                                                <i class="glyphicon glyphicon-play"></i>
                                                @WebApplication1.Utilities.LanguageManager.GetText("Continue")
                                            </a>
                                        }
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="alert alert-info text-center">
            <i class="glyphicon glyphicon-info-sign me-2"></i>
            @WebApplication1.Utilities.LanguageManager.GetText("NoPracticeRecords")
        </div>
    }

    <div class="row mt-4">
        <div class="col-12 text-center">
            <a href="@Url.Action("Index", "Employee")" class="btn btn-secondary btn-lg">
                <i class="glyphicon glyphicon-arrow-left me-2"></i>
                @WebApplication1.Utilities.LanguageManager.GetText("Back")
            </a>
        </div>
    </div>
</div>

<style>
    .card {
        border-radius: 10px;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    }

    .card-header {
        border-radius: 10px 10px 0 0 !important;
    }

    .table th {
        font-weight: 600;
    }

    .table-hover tbody tr:hover {
        background-color: rgba(0, 0, 0, 0.04);
    }

    .badge {
        font-size: 0.85em;
    }

    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 0.75rem 1.5rem;
        font-size: 1.1rem;
    }

    .progress {
        border-radius: 4px;
    }

    .page-header h2 {
        font-weight: 300;
    }

    @@media (max-width: 768px) {
        .table-responsive {
            font-size: 0.85rem;
        }

        .btn-lg {
            padding: 0.5rem 1rem;
            font-size: 1rem;
        }

        .btn-sm {
            padding: 0.2rem 0.4rem;
            font-size: 0.8rem;
        }
    }
</style>